﻿/*
 * Created by SharpDevelop.
 * User: Rogerio
 * Date: 27/01/2009
 * Time: 17:11
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using ComponentFactory.Krypton.Toolkit;

namespace generateKey
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : KryptonForm
	{
   	[DllImport("activation.dll")]
   	public static extern String destroy(String fileName, int numberOfDays);		
   	
   	[DllImport("activation.dll")]
   	public static extern bool setParam(String fileName, String systemName, String param, String value);
   	
   	[DllImport("activation.dll")]
   	public static extern bool createTrialProtection(String fileName, String systemName, int numberDays);
   	
   	[DllImport("activation.dll")]
   	public static extern String getParam(String fileName, String systemName, String param);   	
	
   		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
		}
		
		void BtnGenerateClick(object sender, EventArgs e)
		{
			txtKey.Text = destroy(txtSerie.Text, Convert.ToInt32(txtDaysNumber.Text))+"-"+DateTime.Now.Ticks;
			//txtKey.Text = csharp.common.Util.encrypt(txtDaysNumber.Text);
		}
		
		void BtnLicenceGenerateClick(object sender, EventArgs e)
		{
			String fileName = Application.StartupPath+"\\license.txt";
			String systemName = txtLicenceProgramName.Text;
			int days = Convert.ToInt32(txtLicenceDays.Text);
			
			createTrialProtection(fileName,  systemName, days);
			
			setParam(fileName, systemName, csharp.common.CONSTANTS.paramCustomer, txtLicenceCustomerName.Text);
			setParam(fileName, systemName, csharp.common.CONSTANTS.paramCpfCnpj, txtLicenceCnpj.Text);
			setParam(fileName, systemName, csharp.common.CONSTANTS.paramEmail, txtLicenceEmail.Text);
			
			KryptonMessageBox.Show("Erro: "+getParam(fileName, systemName, csharp.common.CONSTANTS.paramKey));
			csharp.common.LogErro.writeError(getParam(fileName, systemName, csharp.common.CONSTANTS.paramKey));
		}
	}
}
